import axios from 'axios'

export function request(config) {
    const instance = axios.create({
        baseURL: 'http://192.168.0.103:3000'
    })
    
    instance.interceptors.request.use(config => {

        let token = localStorage.getItem('token')
        if (token) {
            config.headers['token'] = token
        }

        return config
    }, err => {
        console.log(err);
    })
    instance.interceptors.response.use(response => {
        if (response.data.msg == '验证失败') {
            this.$router.push('/login')
        }

        return response
    })
    return instance(config)
}